import windows.WindowsMain as WindowsMain
from WindowTotal import Brider
from windows.SubWindows.SubWindow import SubWindow
import tkinter as tk

from windows.SubWindows.SubWindowWidget import WidgetStyleConfig




class WorryViwer(SubWindow):
    def __init__(self, windows: WindowsMain):
        """
        错题查看窗口
        @param windows: WindowsMain 类
        """
        self.titleWSC = WidgetStyleConfig
        self.titleWSC.text = "我的错题本"
        super().__init__(windows)

    def boxPack(self):
        self.SubWindowWidget.title(WidgetStyleConfig=self.titleWSC, position="center")
        # 标题的设置
        frame = self.SubWindowWidget.pack_sub_viewer()
        # Frame的获取
        frame['bg'] = '#2B2B2B'
        TextWorry = tk.Text(frame,font=("黑体", 15))
        TextWorry.place(relwidth=.8, relx=.1,relheight=.8)
        value = Brider.Brider.Apdate(Brider.Brider.readUser(self.window.user))

        TextWorry.insert("insert", "工具提示 F3 字体缩小 F2 字体放大\r\n\r\n\r\n    ")

        TextWorry.insert("insert", value)
        TextWorry.insert("insert", "\r\n以上均为本次错题 None代表未填写")
        Value = 12

        def a(e):
            print("激活")
            nonlocal  Value, TextWorry
            Value += 1
            TextWorry['font'] = ('微软雅黑', Value)
            TextWorry.place(relwidth=.8, relx=.1,relheight=.8)

        def b(e):
            print("激活")
            nonlocal Value, TextWorry
            Value -= 1
            TextWorry['font'] = ('微软雅黑', Value)
            TextWorry.place(relwidth=.8 , relx=.1,relheight=.8)

        def c(e=None):
            nonlocal TextWorry
            list = Brider.Brider.MustCountWorry(self.window.user, 10)
            print(list)
            val = Brider.Brider.Apdate(list, hasCountWorry=True)

            TextWorry.delete('1.0','end')
            TextWorry.insert("insert", "工具提示 F3 字体缩小 F2 字体放大\r\n\r\n\r\n    ")
            TextWorry.insert("insert", val)
            TextWorry.insert("insert", "\r\n以上均为本次错题 None代表未填写")


        self.window.win.bind("<F3>", b)
        self.window.win.bind("<F2>", a)
        btn_top = tk.Button(frame, text='查看错的最多的前10个', command=c)
        btn_top.place(relwidth=.8, rely=.82,relx=.1,)


if __name__ == '__main__':
    ...
